package com.valdemar.tellatale.services;

import java.util.Arrays;
import java.util.List;
import com.stackmob.android.sdk.common.StackMobCommon;
import com.stackmob.sdk.api.StackMob;
import com.stackmob.sdk.callback.StackMobCallback;
import com.stackmob.sdk.exception.StackMobException;
import com.valdemar.tellatale.model.Tail;

public class AddTailService {

	public interface OnAddTailListner {
		public void onSuccess();

		public void onFailure();
	}

	private OnAddTailListner onAddTailListner;

	public void setOnAddTailListner(OnAddTailListner onAddTailListner) {
		this.onAddTailListner = onAddTailListner;
	}

	public AddTailService(OnAddTailListner onAddTailListner) {
		setOnAddTailListner(onAddTailListner);
	}

	public void doAddTail(Tail tail, String taleID) {

		
		StackMob stackMob = StackMobCommon.getStackMobInstance();

		List<Tail> items = Arrays.asList(tail);
		stackMob.postRelatedBulk("Tale", taleID, "tails", items, new StackMobCallback() {
			@Override
			public void success(String responseBody) {
				onAddTailListner.onSuccess();
			}

			@Override
			public void failure(StackMobException e) {
				onAddTailListner.onFailure();
			}
		});
	}

}
